/**
 * @Copyright ®2015 Sinosoft Co. Ltd. All rights reserved.<br/>
 * 项目名称 : 中科软支付平台
 * 创建日期 : 2016年12月14日
 * 修改历史 : 
 *     1. [2016年12月14日]创建文件 by liuyujia
 */
package com.sinosoft.sinopay.web.weixinpay.biz.service.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinosoft.sinocloud.platform.base.SinoBaseCheckException;
import com.sinosoft.sinocloud.platform.base.SinoBaseService;
import com.sinosoft.sinocloud.platform.common.exception.biz.IllegalRequestException;
import com.sinosoft.sinocloud.platform.common.exception.system.SinoSystemException;
import com.sinosoft.sinocloud.platform.common.util.DateUtil;
import com.sinosoft.sinocloud.platform.common.util.HttpClientUtil;
import com.sinosoft.sinocloud.platform.common.util.IpUtil;
import com.sinosoft.sinocloud.platform.common.util.SecurityUtil;
import com.sinosoft.sinocloud.platform.common.util.XStreamComponent;
import com.sinosoft.sinopay.api.common.config.ENUM_PAY_TYPE;
import com.sinosoft.sinopay.api.common.dto.pay.PayAccountInfoDTO;
import com.sinosoft.sinopay.api.common.dto.pay.PaymentInfoDetailDTO;
import com.sinosoft.sinopay.api.common.dto.query.PayInfoQryParam;
import com.sinosoft.sinopay.customer.dto.CustomerInfoDTO;
import com.sinosoft.sinopay.customer.facade.CustomerFacadeService;
import com.sinosoft.sinopay.merchants.dto.MerchantSignInfo;
import com.sinosoft.sinopay.merchants.facade.MerchantInfoFacadeService;
import com.sinosoft.sinopay.paytrade.config.ENUM_PAY_STATUS;
import com.sinosoft.sinopay.paytrade.dto.PayTradeNotifyRecordDTO;
import com.sinosoft.sinopay.paytrade.dto.PaymentConfirmDTO;
import com.sinosoft.sinopay.paytrade.dto.PaymentRequestDTO;
import com.sinosoft.sinopay.paytrade.dto.PaymentTradeReqDTO;
import com.sinosoft.sinopay.paytrade.facade.PaymentTradeFacadeService;
import com.sinosoft.sinopay.paytrade.facade.PaymentTradeQueryFacadeService;
import com.sinosoft.sinopay.web.util.AesUtil;
import com.sinosoft.sinopay.web.util.AmountTransUtil;
import com.sinosoft.sinopay.web.util.RandomStringUtil;
import com.sinosoft.sinopay.web.util.SignatureUtil;
import com.sinosoft.sinopay.web.util.WechatSignUtil;
import com.sinosoft.sinopay.web.weixinpay.biz.config.ENUM_REPORT_NOTIFYTYPE;
import com.sinosoft.sinopay.web.weixinpay.biz.config.WechatConfig;
import com.sinosoft.sinopay.web.weixinpay.biz.config.WechatPaymentConstants;
import com.sinosoft.sinopay.web.weixinpay.biz.service.PaymentWechatService;
import com.sinosoft.sinopay.web.weixinpay.dto.WechatEntryRequsetDTO;
import com.sinosoft.sinopay.web.weixinpay.dto.WechatPaymentResultDTO;
import com.sinosoft.sinopay.web.weixinpay.dto.WechatPrePaymentRequestDTO;
import com.sinosoft.sinopay.web.weixinpay.dto.WechatPrePaymentResultDTO;

/**  
 * 【微信支付服务类】
 * @author liuyujia
 * @date 2016年12月14日 下午2:11:32 
 * @version V1.0  
 */
@Service
public class PaymentWechatServiceImpl extends SinoBaseService implements PaymentWechatService{

	@Autowired
	private PaymentTradeFacadeService paymentTradeFacadeService;
	@Autowired
	private CustomerFacadeService customerFacadeService;
	@Autowired
	private MerchantInfoFacadeService merchantSecurityFacadeService;
	@Autowired
	private PaymentTradeQueryFacadeService paymentTradeQueryFacadeService;
	@Autowired
	private WechatConfig wechatConfig;
	
	/** 商户签名信息缓存map */
	private Map<String, String> signKeysMap;
	 
	AmountTransUtil amountTransUtil=  new AmountTransUtil();
	
	@Override
	public String dealWechatPayRequest(WechatEntryRequsetDTO tWechatEntryRequsetDTO) {
		//持久化客户信息
		CustomerInfoDTO tCustomerInfo = new CustomerInfoDTO();
		tCustomerInfo.setBirthday(tWechatEntryRequsetDTO.getAccountBirthday());
		tCustomerInfo.setCustomerName(tWechatEntryRequsetDTO.getAccountName());
		tCustomerInfo.setGender(tWechatEntryRequsetDTO.getAccountGender());
		tCustomerInfo.setMechantCode(tWechatEntryRequsetDTO.getMerchantCode());
		tCustomerInfo.setIdNo(tWechatEntryRequsetDTO.getIdNo());
		tCustomerInfo.setIdType(tWechatEntryRequsetDTO.getIdType());
		//持久化交易信息
		PaymentRequestDTO tPaymentRequest = new PaymentRequestDTO();
		tPaymentRequest.setMerchantCode(tWechatEntryRequsetDTO.getMerchantCode());
		tPaymentRequest.setBizNo(tWechatEntryRequsetDTO.getBizNo());
		tPaymentRequest.setBizType(tWechatEntryRequsetDTO.getBizType());
		tPaymentRequest.setSerialNo(tWechatEntryRequsetDTO.getSerialNo());
		tPaymentRequest.setPayAmount(tWechatEntryRequsetDTO.getPayAmount());
		tPaymentRequest.setRemark(tWechatEntryRequsetDTO.getTransDesc());
		tPaymentRequest.setCreateDate(tWechatEntryRequsetDTO.getRequestDate());
		
		//持久化账户信息
		PayAccountInfoDTO tPayAccountInfo = new PayAccountInfoDTO();
		tPayAccountInfo.setAccountName(tWechatEntryRequsetDTO.getAccountName());
		tPayAccountInfo.setCardType(tWechatEntryRequsetDTO.getIdType());
		tPayAccountInfo.setCardNo(tWechatEntryRequsetDTO.getIdNo());
		tPaymentRequest.setPayAccount(tPayAccountInfo);
		//调用客户服务  老客户返回1, 新客户返回0
		Integer customer = customerFacadeService.saveCustomerPayAccountInfo(tPayAccountInfo);
		logger.info("客户增改标记："+customer);
		//调用交易服务
		String tPayNo = paymentTradeFacadeService.newPayTrade(tPaymentRequest);
		//生成合法支付链接地址
		Long timestap = new Date().getTime();
		tWechatEntryRequsetDTO.setRemark(tPayNo);
		//签名算法
		String signMsg = getMerchantSignValid(tWechatEntryRequsetDTO.getMerchantCode(), tWechatEntryRequsetDTO);
		logger.info("返回URL参数签名:"+signMsg);
		StringBuffer tPayUrl = new StringBuffer(WechatPaymentConstants.PAY_REQUEST_URL);
		tPayUrl.append("payNo=");
		tPayUrl.append(tPayNo);
		tPayUrl.append("&orderNo=");
		tPayUrl.append(tWechatEntryRequsetDTO.getBizNo());
		tPayUrl.append("&signMsg=");
		tPayUrl.append(signMsg);
		tPayUrl.append("&t=");
		tPayUrl.append(timestap);
		//3.返回支付URL
		return tPayUrl.toString();
	}

	@Override
	public String getAuthorizeInfo(String authorizeInfo) throws UnsupportedEncodingException {
		String redirectUri = wechatConfig.getWechatRedirectUri();
		logger.info("微信授权地址为:"+redirectUri);
		//如果参数不为空，拼接参数
		if(StringUtils.isNotEmpty(authorizeInfo)){
			redirectUri=redirectUri+"?"+authorizeInfo;
		}
		//地址进行encode处理
		redirectUri = URLEncoder.encode(redirectUri, "utf-8");
		//封装授权地址
		StringBuffer sb = new StringBuffer();
		sb.append(WechatPaymentConstants.AUTHORIZE_URL);
		sb.append("?appid=").append(wechatConfig.getWechatAppid());
		sb.append("&redirect_uri=").append(redirectUri);
		sb.append("&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect");
		return sb.toString();
	}

	@Override
	public String getMerchantSignValid(String merchantCode, WechatEntryRequsetDTO tWechatEntryRequsetDTO) throws IllegalRequestException {
		logger.info("准备签名......");
		if(signKeysMap==null || signKeysMap.size()==0){
			 //获取全部的商户签名信息
			 signKeysMap = merchantSecurityFacadeService.getAllMerchantSignKeys();
		 }
		//获取商户对应的key值
		if(signKeysMap.get(merchantCode)==null){
			throw new IllegalRequestException("商户不存在");
		}
		String tSignKey = signKeysMap.get(merchantCode);
		//封装签名参数
		Map<String,String> tSignInfoMap = new HashMap<String,String>();
		tSignInfoMap.put("merchantCode",merchantCode);
        tSignInfoMap.put("bizNo", tWechatEntryRequsetDTO.getBizNo());
        tSignInfoMap.put("bizType", tWechatEntryRequsetDTO.getBizType());
        tSignInfoMap.put("transType", tWechatEntryRequsetDTO.getTransType());
        tSignInfoMap.put("transDesc", tWechatEntryRequsetDTO.getTransDesc());
        tSignInfoMap.put("serialNo", tWechatEntryRequsetDTO.getSerialNo());
        tSignInfoMap.put("accountName", tWechatEntryRequsetDTO.getAccountName());
       
        tSignInfoMap.put("idType", tWechatEntryRequsetDTO.getIdType());
        //证件类型为身份证时执行
        if("1".equals(tWechatEntryRequsetDTO.getIdType()) && tWechatEntryRequsetDTO.getIdType()!=null){
        	 tSignInfoMap.put("accountGender", tWechatEntryRequsetDTO.getAccountGender());
             Date tAccountBirthday = tWechatEntryRequsetDTO.getAccountBirthday();
             String birthday = DateUtil.getDateStr(tAccountBirthday, "yyyy-MM-dd");
             tSignInfoMap.put("accountBirthday", birthday);
        }
        else{
        	 tSignInfoMap.put("accountGender","");
             tSignInfoMap.put("accountBirthday", "");
        }
        tSignInfoMap.put("idNo", tWechatEntryRequsetDTO.getIdNo());
        String tPayAmount = amountTransUtil.transAmount(tWechatEntryRequsetDTO.getPayAmount());
        tSignInfoMap.put("payAmount",tPayAmount);//金额转换成分
        Date tRequestDate = tWechatEntryRequsetDTO.getRequestDate();
        String date = DateUtil.getDateStr(tRequestDate, "yyyy-MM-dd");
        tSignInfoMap.put("requestDate",date);
        tSignInfoMap.put("remark", tWechatEntryRequsetDTO.getRemark());
        logger.info(new Date()+"签名参数:"+tSignInfoMap.toString());
        String tCompareSignMsg = WechatSignUtil.encryMD5(tSignInfoMap,tSignKey);
		return tCompareSignMsg;
	}

	@Override
	public String getOpenidByCode(String code) throws Exception {
		//封装请请求地址
		StringBuffer sb = new StringBuffer();
		sb.append(WechatPaymentConstants.TOKEN_URL);
		sb.append("?appid=").append(wechatConfig.getWechatAppid());
		sb.append("&secret=").append(wechatConfig.getWechatAppSecret());
		sb.append("&code=").append(code);
		sb.append("&grant_type=authorization_code");
		logger.info("获取code请求地址:"+sb.toString());
		String accessInfo = HttpClientUtil.originalGetData(sb.toString());
		logger.info("getOpenidByCode请求:"+accessInfo);
		return accessInfo;
	}

	@Override
	public PaymentInfoDetailDTO getPaymentTradeForPayNo(String payNo) {
//		PayInfoQryParam tPayInfoQryParam = new PayInfoQryParam();
//		tPayInfoQryParam.setPayNo(payNo);
		logger.info("获取订单信息开始......");
		PaymentInfoDetailDTO pPaymentInfoDetailDTO = paymentTradeQueryFacadeService.queryPaymentOrderByPayNo(payNo);
		if(pPaymentInfoDetailDTO==null){
			throw new IllegalRequestException("商户不存在");
		}
		return pPaymentInfoDetailDTO;
	}

	@Override
	public WechatPaymentResultDTO wechatPrePayment(String payNo, String openid) throws SinoBaseCheckException, Exception{
		// TODO Auto-generated method stub
		logger.info("统一下单支付开始......");
		PaymentInfoDetailDTO wPaymentInfoDetailDTO = getPaymentTradeForPayNo(payNo);
		//准备统一下单参数
		WechatPrePaymentRequestDTO wWechatPrePaymentRequestDTO = new WechatPrePaymentRequestDTO();
	    wWechatPrePaymentRequestDTO.setAppid(wechatConfig.getWechatAppid());//公众账号ID
	    wWechatPrePaymentRequestDTO.setMch_id(wechatConfig.getWechatMchid());//商户号
	    wWechatPrePaymentRequestDTO.setDevice_info("WEB");//设备号
	    wWechatPrePaymentRequestDTO.setNonce_str(RandomStringUtil.getRandomString32());//随机字符串
	    wWechatPrePaymentRequestDTO.setBody(wPaymentInfoDetailDTO.getTradeDesc());//商品描述
	    wWechatPrePaymentRequestDTO.setOut_trade_no(payNo);//商户订单号
	    wWechatPrePaymentRequestDTO.setFee_type("CNY");//货币类型
	    String tPayAmount = amountTransUtil.transAmount(wPaymentInfoDetailDTO.getPayAmount());
	    wWechatPrePaymentRequestDTO.setTotal_fee(Integer.valueOf(tPayAmount));//总金额
	    wWechatPrePaymentRequestDTO.setSpbill_create_ip(IpUtil.getLocalIP());//终端IP
	    wWechatPrePaymentRequestDTO.setNotify_url(wechatConfig.getWechatNotifyUrl());//通知地址
	    wWechatPrePaymentRequestDTO.setTrade_type("JSAPI");//交易类型
	    wWechatPrePaymentRequestDTO.setOpenid(openid);//用户标识
	    String sign = WechatSignUtil.getSign(wWechatPrePaymentRequestDTO.toMap(), wechatConfig.getWechatKey());
	    wWechatPrePaymentRequestDTO.setSign(sign);//签名
	    wWechatPrePaymentRequestDTO.createXml();
	    //传输报文
	    String requestXML = wWechatPrePaymentRequestDTO.getXml();
	    logger.info("统一下单请求报文:"+requestXML);
	    //统一下单请求
        String responseXML =HttpClientUtil.postJsonData(WechatPaymentConstants.ORDER_URL, requestXML, "utf-8");
        logger.info("统一下单返回报文:"+responseXML);
        //解析返回，并返回订单参数
        XStreamComponent xStreamComponent = XStreamComponent.newInstance();
        xStreamComponent.processAnnotations(WechatPrePaymentResultDTO.class);
        WechatPrePaymentResultDTO tWechatPrePaymentResultDTO =  (WechatPrePaymentResultDTO)xStreamComponent.fromXML(responseXML);
        WechatPaymentResultDTO tWechatPaymentResultDTO = new WechatPaymentResultDTO();
        if("SUCCESS".equals(tWechatPrePaymentResultDTO.getResult_code()) && 
        		"SUCCESS".equals(tWechatPrePaymentResultDTO.getReturn_code())){
        	String timeStamp = Long.toString(System.currentTimeMillis() / 1000);
        	String nonceStr = tWechatPrePaymentResultDTO.getNonce_str();
        	tWechatPaymentResultDTO.setAppId(tWechatPrePaymentResultDTO.getAppid());
        	tWechatPaymentResultDTO.setTimeStamp(timeStamp);
        	tWechatPaymentResultDTO.setNonceStr(nonceStr);
        	tWechatPaymentResultDTO.setSignType("MD5");
        	tWechatPaymentResultDTO.setPackages("prepay_id="+tWechatPrePaymentResultDTO.getPrepay_id());
        	StringBuffer sb = new StringBuffer();
        	sb.append("appId=").append(tWechatPaymentResultDTO.getAppId());
    		sb.append("&nonceStr=").append(tWechatPaymentResultDTO.getNonceStr());
    		sb.append("&package=").append(tWechatPaymentResultDTO.getPackages());
    		sb.append("&signType=").append(tWechatPaymentResultDTO.getSignType());
    		sb.append("&timeStamp=").append(tWechatPaymentResultDTO.getTimeStamp());
    		String paySign = sb.toString()+"&key="+wechatConfig.getWechatKey();
    		paySign = SecurityUtil.Md5(paySign).toUpperCase();
    		tWechatPaymentResultDTO.setPaySign(paySign);
    		tWechatPaymentResultDTO.setPayNo(payNo);
    		tWechatPaymentResultDTO.setReturnCode("000000");//
    		tWechatPaymentResultDTO.setPayAmount(wPaymentInfoDetailDTO.getPayAmount());
    		String signature = Signature(nonceStr,payNo,timeStamp);
    		tWechatPaymentResultDTO.setSignature(signature);
        }else{
        	tWechatPaymentResultDTO.setReturnCode("111111");
        	tWechatPaymentResultDTO.setReturnDesc(tWechatPrePaymentResultDTO.getReturn_msg());
        }
		return tWechatPaymentResultDTO;
	}

	public String Signature(String nonceStr, String outTradeNo, String timestamp){
		logger.info("获取access_token开始!!!");
		String access_token ="";
		String jsapi_ticket = "";
		 try {
			//获取access_token
			 Map<String,String> paramMap = new HashMap<String,String>();
			 JSONObject actoken = new JSONObject();
			 actoken.put("useType", wechatConfig.getUseType());
			 actoken.put("accountNo", wechatConfig.getAcNo());
			 StringBuffer sb = new StringBuffer();
			 Map<String,String> md5Data = new TreeMap<String,String>();
				md5Data.put("useType", wechatConfig.getUseType());
				md5Data.put("accountNo", wechatConfig.getAcNo());
				for(String key : md5Data.keySet()){
		        	String value = md5Data.get(key);
		        	if (StringUtils.isEmpty(value)) {
		            	continue;
		            }
		        	sb.append(value);
		        }
			logger.info("获取token报文数据:"+actoken.toString());
//			String data = SecurityUtil.aesEncrypt(actoken.toString(),"123123");//TODO
//			String sign = SecurityUtil.signMD5(sb.toString(), wechatConfig.getAcSign());
			String 	data = AesUtil.encryptAES(actoken.toString());
			String 	sign = SignatureUtil.PaySignature(md5Data, "abc123");
	        paramMap.put("data", data);
	        paramMap.put("sign", sign);
			String accessTokenUrl = wechatConfig.getAccessTokenUrl();
			System.out.println("开始请求");
			logger.info("data="+data+"&sign="+sign);
			JSONObject response = JSONObject.fromObject(HttpClientUtil.postData(accessTokenUrl, paramMap));
			logger.info("返回报文为:"+response);
			access_token = response.getString("accessToken");
			jsapi_ticket = response.getString("jsapi_ticket");
			logger.info("access_token="+access_token);
			logger.info("jsapi_ticket="+jsapi_ticket);
		} catch (Exception e) {
			logger.info("获取access_token/jsapi_ticket异常");
			e.printStackTrace();
		}
	        //获取签名signature
	        String url=WechatPaymentConstants.PAY_SIGNATURE+outTradeNo;
	        String str = "jsapi_ticket=" + jsapi_ticket +
	                "&noncestr=" + nonceStr +
	                "&timestamp=" + timestamp +
	                "&url=" + url;
	        logger.info("SHA1前字符串：");
	        //SHA1加密
	        String signature = SecurityUtil.SHA1(str);
	        logger.info("noncestr=" + nonceStr);
	        logger.info("timestamp=" + timestamp);
	        logger.info("signature=" + signature);
	        //最终获得调用微信js接口验证需要的三个参数noncestr、timestamp、signature
	        return signature;
	}

	@Override
	public String getNotifyUrlByMerchant(String merchantCode, String notifyWay) {
		String notifyUrl = null;
		MerchantSignInfo tMerchantSignInfo = merchantSecurityFacadeService.getMerchantByCode(merchantCode);
		if(notifyWay==ENUM_REPORT_NOTIFYTYPE.PAGE_NOTIFY.code()){
			notifyUrl = tMerchantSignInfo.getPayPageNotifyURL();
		}
		else
			notifyUrl = tMerchantSignInfo.getPayBackNotifyURL();
		return notifyUrl;
	}

	@Override
	public void addPaymentInfo(String payNo) throws Exception {
		PaymentInfoDetailDTO tPaymentInfoDetailDTO = getPaymentTradeForPayNo(payNo);
		PaymentTradeReqDTO cPaymentTradeReqDTO = new PaymentTradeReqDTO();
		cPaymentTradeReqDTO.setSerialNo(tPaymentInfoDetailDTO.getSerialNo());
		cPaymentTradeReqDTO.setBizNo(tPaymentInfoDetailDTO.getBizNo());
		cPaymentTradeReqDTO.setPayNo(payNo);
		cPaymentTradeReqDTO.setMerchantCode(tPaymentInfoDetailDTO.getMerchantCode());
		cPaymentTradeReqDTO.setThirdpayCode(tPaymentInfoDetailDTO.getThirdpayCode());
		cPaymentTradeReqDTO.setBizType(tPaymentInfoDetailDTO.getBizType());
		cPaymentTradeReqDTO.setPayWay("");
		cPaymentTradeReqDTO.setPayType(ENUM_PAY_TYPE.WXPAY.code());
		cPaymentTradeReqDTO.setPayStatus(ENUM_PAY_STATUS.PAY_WAIT.code());
		cPaymentTradeReqDTO.setPayAmount(tPaymentInfoDetailDTO.getPayAmount());
		cPaymentTradeReqDTO.setPayDate(tPaymentInfoDetailDTO.getPayDate());
		cPaymentTradeReqDTO.setTradeDesc(tPaymentInfoDetailDTO.getTradeDesc());
		cPaymentTradeReqDTO.setPayAccountName(tPaymentInfoDetailDTO.getAccountName());
		cPaymentTradeReqDTO.setPayIdType(tPaymentInfoDetailDTO.getIdType());
		cPaymentTradeReqDTO.setPayIdNo(tPaymentInfoDetailDTO.getIdNo());
		cPaymentTradeReqDTO.setPayAccountMobile(tPaymentInfoDetailDTO.getMobile());
		cPaymentTradeReqDTO.setCurrency("CNY");
		cPaymentTradeReqDTO.setCreateDate(new Date());
		paymentTradeFacadeService.addPaymentInfo(cPaymentTradeReqDTO);
	}

	@Override
	public void addPayTradeNotifyRecordByChanel(PaymentInfoDetailDTO tPaymentInfoDetailDTO) throws Exception {
		PayTradeNotifyRecordDTO cPayTradeNotifyRecordDTO = new PayTradeNotifyRecordDTO();
		cPayTradeNotifyRecordDTO.setMerchantCode(tPaymentInfoDetailDTO.getMerchantCode());
		cPayTradeNotifyRecordDTO.setPayNo(tPaymentInfoDetailDTO.getPayNo());
		String notifyUrl = getNotifyUrlByMerchant(tPaymentInfoDetailDTO.getMerchantCode(), ENUM_REPORT_NOTIFYTYPE.BACK_NOTIFY.code());
		cPayTradeNotifyRecordDTO.setNotifyUrl(notifyUrl);
		cPayTradeNotifyRecordDTO.setNotifyType(ENUM_REPORT_NOTIFYTYPE.BACK_NOTIFY.code());
		cPayTradeNotifyRecordDTO.setNotifyTimes(0);
		cPayTradeNotifyRecordDTO.setLimitNotifyTimes(3);
		cPayTradeNotifyRecordDTO.setCreateDate(new Date());
		paymentTradeFacadeService.addPayTradeNotifyRecord(cPayTradeNotifyRecordDTO);
		
	}

	@Override
	public void modifyTradeOrderStatus(String payNo, String payStatus) throws Exception {
		PaymentConfirmDTO cPayConfirmInfo = new PaymentConfirmDTO();
		cPayConfirmInfo.setPayNo(payNo);
		cPayConfirmInfo.setPayStatus(payStatus);
		int tradeOrderLow = paymentTradeFacadeService.modifyTradeOrderStatus(cPayConfirmInfo);
		if(tradeOrderLow<0){
			logger.info("更新数据失败");
			throw new SinoSystemException("更新数据失败"); 
		}
	}

	@Override
	public void modifyPaymentInfo(PaymentTradeReqDTO cPaymentTradeReqDTO) throws Exception {
		int payInfo = paymentTradeFacadeService.modifyPaymentInfo(cPaymentTradeReqDTO);
		if(payInfo<0){
			logger.info("更新数据失败");
			throw new SinoSystemException("更新数据失败"); 
		}
	}

	@Override
	public List<PayTradeNotifyRecordDTO> queryPayTradeNotifyRecord(String payNo) throws Exception {
		PayTradeNotifyRecordDTO cPayTradeNotifyRecord = new PayTradeNotifyRecordDTO();
		cPayTradeNotifyRecord.setPayNo(payNo);
		return paymentTradeQueryFacadeService.queryPayTradeNotifyRecord(cPayTradeNotifyRecord);
	}

	@Override
	public void addPayTradeNotifyRecord(PayTradeNotifyRecordDTO cPayTradeNotifyRecordDTO) throws Exception {
		int notify = paymentTradeFacadeService.addPayTradeNotifyRecord(cPayTradeNotifyRecordDTO);
		if(notify<0){
			throw new SinoSystemException("更新数据失败"); 
		}
	}
}
